<template>
    <div v-if="homedata">
       <header>
           <img src="https://mfs.ys7.com/mall/7c4f0ac3d58e9b3629a3748208e6899d.png"/>
           <div @click="handleSearch">
               <input type="text" disabled placeholder="搜索商品">
               <img src="https://mfs.ys7.com/mall/9be4a39ef98f84fcce854911ca2619aa.png">
           </div>
           <img src="https://mfs.ys7.com/mall/4041c962bea816b560a81e170ca0a626.png"/>
       </header>
       <main>
            <div class="carousel">
                <van-swipe indicator-color="#fe974d"  class="vantswip" :autoplay="2000">
                    <van-swipe-item  v-for="item,index in homedata.page.data[1].data" :key="index">
                        <img :src="item.imgUrl">
                    </van-swipe-item>
                </van-swipe>
            </div>
            <ul class="navmenu">
                <li>
                    <img src="../assets/img/home-xpsf.png" alt="">
                    <img src="../assets/img/home-xin.png" alt="">
                    <span>新品首发</span>
                </li>
                <li>
                    <img src="../assets/img/home-spms.png" alt="">
                    <span>限时秒杀</span>
                </li>
                <li>
                    <img src="../assets/img/home-xsfw.png" alt="">
                    <span>上门服务</span>
                </li>
                <li>
                    <img src="../assets/img/home-spms.png" alt="">
                    <span>视频门锁</span>
                </li>
                <li>
                    <img src="../assets/img/home-sptz.png" alt="">
                    <span>商铺套装</span>
                </li>
                <li>
                    <img src="../assets/img/home-mfsy.png" alt="">
                    <span>免费试用</span>
                </li>
                <li>
                    <img src="../assets/img/home-hptj.png" alt="">
                    <span>好评推荐</span>
                </li>
                <li>
                    <img src="../assets/img/home-qwzn.png" alt="">
                    <span>全屋智能</span>
                </li>
            </ul>
       </main>
        <div class="recom">
            <div class="forcheap">
                <a href="#" v-for="item,index in this.homedata.page.data[4].data" :key="index">
                    <img :src="item.imgUrl">
                </a>
            </div>
            <div class="forpresell">
                <div>
                    <h3>{{this.homedata.page.data[5].data.book_item_data.title}}</h3>
                    <a href="#">查看更多  &gt;</a>
                </div>
                <div>
                      <ul ref="pregoods">
                        <li v-for="item,index in this.homedata.page.data[5].data.book_item_data.book_items" :key="index">
                            <img :src="item.goods_img">
                            <span>距结束1天多少秒</span>
                            <h6>{{item.goods_name}}</h6>
                            <p>到手价<span>{{item.final_price}}</span><i>起</i></p>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="shoplist">
            <div ref="listnav">
              <ul>
                <li
                  :class="{ active: listIndex == index }"
                  v-for="(item, index) in homedata.tabs"
                  :key="index"
                  @click="handleCut(index)"
                >
                  <a href="#">{{ item.tagName }}</a>
                  <span></span>
                </li>
              </ul>
            </div>
            <ul>
              <li v-show="listIndex == 1">
                <img
                  class="for_img"
                  src="	https://mfs.ys7.com/mall/41be1ea6479aaabe4d44376ebd015273.png"
                  alt=""
                />
              </li>

              <li
                v-for="(item, index) in homedata.tabs[listIndex].data[0].data
                  .goods"
                :key="index"
              >
                <router-link :to="`/detail/${item.good.goodsId}`">
                  <img :src="item.good.fullImageUrl" />
                  <h6><span>限时直降</span>{{ item.good.name }}</h6>
                  <p>
                    <i
                      ><span
                        v-for="(itm, idx) in dataSplit(item.good.selling_point)"
                        :key="idx"
                        >{{ itm }}</span
                      ></i
                    >
                    <b v-show="!item.good.selling_point">{{
                      item.good.brief
                    }}</b>
                  </p>
                  <div>
                    <span>￥{{ item.price.low }}</span
                    ><i>起</i><b>￥{{ item.price.high }}</b>
                  </div>
                </router-link>
              </li>
            </ul>
          </div>
      <div>
        <a href="#" class="forhelp">
            <img src="../assets/img/home-lianxi.png" alt="" />
        </a>
    </div>
  </div>
</template>
 
<script>
import instance from "../utils/request";
export default {
  data() {
    return {
      homedata: null,
      listIndex: 0,
    };
  },
  methods: {
    handleCut(i) {
      this.listIndex = i;
    },
    dataSplit(str) {
      return str ? str.split("|").slice(0, 2) : 0;
    },
    handleSearch(){
      this.$router.push('/search')
    }
  },
  created() {
    instance.get("/yingshi/default/index-h5").then((res) => {
      this.homedata = res.data.data;
    });
  },
  mounted() {
    document.onscroll = () => {
      let { listnav } = this.$refs;
      if (listnav) {
        if (document.documentElement.scrollTop >= 811) {
          listnav.style.position = "fixed";
          listnav.style.top = ".51rem";
          listnav.style.background = "white";
        } else {
          listnav.style.position = "relative";
          listnav.style.top = "0";
          listnav.style.background = "#f8f8f8";
        }
      }
    };
  },
};
</script>

<style lang="less" scoped>
@allcolor: #fe974d;
header {
  position: fixed;
  width: 100%;
  height: 0.51rem;
  background: @allcolor;
  padding: 0 0.16rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
  div {
    width: 2.76rem;
    height: 0.28rem;
    position: relative;
    box-sizing: border-box;
    background: white;
    border-radius: 0.14rem;
    overflow: hidden;
    input {
      width: 100%;
      height: 100%;
      outline: none;
      border: none;
      padding-left: 0.4rem;
      font-size: 0.14rem;
    }
    img {
      position: absolute;
      top: 0.04rem;
      left: 0.16rem;
      width: 0.2rem;
      height: 0.2rem;
    }
  }
  > img {
    width: 0.25rem;
    height: 0.25rem;
  }
}
main {
  padding: 0.515rem 0.16rem 0;
  background: linear-gradient(to bottom, @allcolor 25%, #f8f8f8 75%);
  .carousel {
    height: 1.58rem;
    box-sizing: border-box;
    margin: 0.07rem 0;
    border-radius: 0.09rem;
    overflow: hidden;
    .vantswip {
      height: 100%;
      .van-swipe-item {
        height: 100%;
        width: 10.11rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .van-swipe__indicator--active {
        background-color: #333;
      }
    }
  }
  .navmenu {
    height: 1.69rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-content: space-between;
    box-sizing: border-box;
    padding: 0.1rem 0;
    li {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: center;
      margin-right: 0.2rem;
      img {
        width: 0.56rem;
      }
      span {
        color: #333;
        font-size: 0.12rem;
      }
    }
    li:first-child {
      position: relative;
      img:nth-child(2) {
        width: 0.15rem;
        position: absolute;
        top: 0;
        right: 0;
      }
    }
    li:nth-child(4),
    li:nth-child(8) {
      margin-right: 0;
    }
  }
}
.recom {
  padding: 0.1rem 0.16rem;
  background: #f8f8f8;
  .forcheap {
    display: flex;
    height: 2.03rem;
    padding-bottom: 0.1rem;
    box-sizing: border-box;
    flex-wrap: wrap;
    justify-content: space-between;
    align-content: space-between;
    a {
      display: inline-block;
      width: 1.7rem;
      height: 0.95rem;
      border-radius: 0.04rem;
      overflow: hidden;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
  .forpresell {
    background: white;
    height: 2.46rem;
    box-sizing: border-box;
    padding: 0.12rem 0;
    border-radius: 0.05rem;
    overflow: hidden;
    div:first-child {
      display: flex;
      justify-content: space-between;
      height: 0.18rem;
      padding: 0 0.14rem;
      h3 {
        font-weight: 900;
        font-size: 0.16rem;
      }
      a {
        color: #777;
        font-size: 0.12rem;
      }
    }
    div:nth-child(2) {
      overflow: auto;
      height: 2.28rem;
      width: 100%;
      ul {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.08rem;
        li {
          margin: 0.08rem;
          width: 1.16rem;
          height: 1.83rem;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
          img {
            width: 1.16rem;
            height: 1.16rem;
            border-radius: 0.03rem;
          }
          > span {
            font-size: 0.12rem;
            color: #fa2828;
          }
          h6 {
            font-size: 0.14rem;
            color: #020202;
            width: 100%;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
          }
          p {
            color: @allcolor;
            font-size: 0.12rem;
            span {
              font-size: 0.14rem;
              font-weight: 900;
            }
            i {
              font-weight: 900;
            }
          }
        }
      }
    }
  }
}
.shoplist {
  background: #f8f8f8;
  padding: 0 0.16rem 0.5rem;
  overflow: hidden;
  > div:nth-child(1)::-webkit-scrollbar {
    width: 0;
    height: 0;
  }
  > div:nth-child(1) {
    height: 0.44rem;
    width: 100%;
    overflow: auto;
    position: relative;
    top: 0;
    left: 0;
    background: #f8f8f8;
    ul:nth-child(1) {
      display: flex;
      height: 0.44rem;
      justify-content: space-between;
      align-items: center;
      .active {
        font-size: 0.18rem;
        font-weight: 900;
        a {
          color: @allcolor;
        }
        span {
          width: 0.3rem;
          display: inline-block;
        }
      }
      li {
        margin-right: 0.2rem;
        font-size: 0.16rem;
        height: 0.44rem;
        line-height: 0.44rem;
        white-space: nowrap;
        position: relative;
        vertical-align: center;
        span {
          display: none;
          width: 100%;
          height: 0.04rem;
          border-radius: 0.02rem;
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
          bottom: 0;
          background: @allcolor;
          transition: all 0.1s;
        }
        a {
          color: #171717;
          display: block;
          width: 100%;
          line-height: 0.44rem;
          pointer-events: none;
        }
      }
      li:last-child {
        margin-right: 0;
      }
    }
  }
  ul:nth-child(2) {
    padding-top: 0.12rem;
    display: flex;
    justify-content: space-between;
    align-content: space-between;
    flex-wrap: wrap;
    @width: 1.68rem;
    li {
      padding-bottom: 0.12rem;
      display: flex;
      width: @width;
      flex-direction: column;
      justify-content: space-between;
      background: white;
      margin: 0.07rem 0;
      height: 3rem;
      box-sizing: border-box;
      border-radius: 0.06rem;
      overflow: hidden;
      img {
        width: @width;
        height: @width;
        margin-bottom: 0.12rem;
      }
      .for_img {
        height: 3rem;
      }
      h6 {
        height: 0.48rem;
        line-height: 0.23rem;
        overflow: hidden;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        text-overflow: ellipsis;
        font-size: 0.14rem;
        color: #171717;
        padding: 0 0.1rem;
        span {
          display: inline-block;
          width: 0.54rem;
          height: 0.18rem;
          color: white;
          border-radius: 0.09rem;
          font-size: 0.12rem;
          background: #fc3d2e;
          text-align: center;
          line-height: 0.18rem;
          padding: 0 0.02rem;
        }
      }
      p {
        font-size: 0.12rem;
        color: #777;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 0 0.1rem;
        span {
          display: inline-block;
          height: 0.16rem;
          border-radius: 0.09rem;
          font-size: 0.12rem;
          text-align: center;
          line-height: 0.16rem;
          border: 0.01rem solid #777;
          padding: 0 0.02rem;
          margin-right: 0.04rem;
        }
      }
      div {
        padding: 0 0.1rem;
        span {
          font-size: 0.15rem;
          color: @allcolor;
          font-weight: 900;
        }
        i {
          font-size: 0.12rem;
          color: @allcolor;
          font-weight: 900;
          margin-right: 0.01rem;
        }
        b {
          font-size: 0.12rem;
          color: #aaa;
          text-decoration: line-through;
        }
      }
    }
  }
}
.forhelp {
  display: inline-block;
  position: fixed;
  left: 0.2rem;
  bottom: 0.7rem;
  width: 0.46rem;
  height: 0.46rem;
  border-radius: 50%;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>